﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Csla;

    using MarketPulse.BusinessLogic.Core;
    using MarketPulse.Reporting.Core.Criteria;

#endregion

namespace MarketPulse.Reporting.Core
{
    /// <summary>
    /// This class represents a collection of ReportingQuestions
    /// </summary>
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.ReportingQuestionFactory, MarketPulse.DataAccess.Factory", "FetchInfoList")]
    public class ReportingQuestionInfoList : MarketPulseReadOnlyListBase<ReportingQuestionInfoList, ReportingQuestionInfo>
    {

        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private ReportingQuestionInfoList()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                /// <summary>
                /// Retrieves a list of ReportingQuestionInfo objects for a given VisitID and VisitVersionID.
                /// </summary>
                /// <param name="clientGUID">The ClientGUID to get ReportingQuestionInfo objects for.</param>
                /// <param name="visitID">The VisitID to get ReportingQuestionInfo objects for.</param>
                /// <param name="visitVersionID">The VisitVersionID to get ReportingQuestionInfo objects for.</param>
                /// <returns></returns>
                public static ReportingQuestionInfoList GetByClientGUIDAndVisitIDAndVisitVersionID(Guid clientGUID, long visitID, int visitVersionID)
                {
                    return DataPortal.Fetch<ReportingQuestionInfoList>(new ClientGUIDAndVisitIDAndVisitVersionIDCriteria(clientGUID, visitID, visitVersionID));
                }
    
            #endregion

            #region Exposed Methods

                /// <summary>
                /// Retrieve a list of QuestionInfo items from this collection which have the given reference.
                /// </summary>
                /// <param name="referenceKey">The reference key to search on.</param>
                /// <returns>A list of ReportingQuestionInfo objects which contains the reference specified.</returns>
                public List<ReportingQuestionInfo> GetByReference(string referenceKey)
                {
                    return this.Items.Where(q => q.HasReference(referenceKey)).ToList();
                }

            #endregion

        #endregion
    }
}
